home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bisonpcb.zip / BISON.HAI < prev    next >
Text File  |  1987-02-13  |  7KB  |  341 lines

  1.  
  2. extern int timeclock;
  3.  
  4.  
  5. int yyerror;        /*  Yyerror and yycost are set by guards.    */
  6. int yycost;        /*  If yyerror is set to a nonzero value by a    */
  7.             /*  guard, the reduction with which the guard    */
  8.             /*  is associated is not performed, and the    */
  9.             /*  error recovery mechanism is invoked.    */
  10.             /*  Yycost indicates the cost of performing    */
  11.             /*  the reduction given the attributes of the    */
  12.             /*  symbols.                    */
  13.  
  14.  
  15. #define    YYACCEPT    return (0)
  16. #define    YYABORT        return (1)
  17.  
  18.  
  19. /*  YYMAXDEPTH indicates the size of the parser's state and value    */
  20. /*  stacks.                                */
  21.  
  22. #ifndef    YYMAXDEPTH
  23. #define    YYMAXDEPTH    500
  24. #endif
  25.  
  26. /*  YYMAXRULES must be at least as large as the number of rules that    */
  27. /*  could be placed in the rule queue.  That number could be determined    */
  28. /*  from the grammar and the size of the stack, but, as yet, it is not.    */
  29.  
  30. #ifndef    YYMAXRULES
  31. #define    YYMAXRULES    100
  32. #endif
  33.  
  34. #ifndef    YYMAXBACKUP
  35. #define YYMAXBACKUP    100
  36. #endif
  37.  
  38.  
  39. short    yyss[YYMAXDEPTH];    /*  the state stack            */
  40. YYSTYPE    yyvs[YYMAXDEPTH];    /*  the semantic value stack        */
  41. YYLTYPE yyls[YYMAXDEPTH];    /*  the location stack            */
  42. short    yyrq[YYMAXRULES];    /*  the rule queue            */
  43. int    yychar;            /*  the lookahead symbol        */
  44.  
  45. YYSTYPE    yylval;            /*  the semantic value of the        */
  46.                 /*  lookahead symbol            */
  47.  
  48. YYSTYPE yytval;            /*  the semantic value for the state    */
  49.                 /*  at the top of the state stack.    */
  50.  
  51. YYSTYPE yyval;            /*  the variable used to return        */
  52.                 /*  semantic values from the action    */
  53.                 /*  routines                */
  54.  
  55. YYLTYPE yylloc;        /*  location data for the lookahead    */
  56.                 /*  symbol                */
  57.  
  58. YYLTYPE yytloc;        /*  location data for the state at the    */
  59.                 /*  top of the state stack        */
  60.  
  61.  
  62. int    yynunlexed;
  63. short    yyunchar[YYMAXBACKUP];
  64. YYSTYPE    yyunval[YYMAXBACKUP];
  65. YYLTYPE yyunloc[YYMAXBACKUP];
  66.  
  67. short *yygssp;            /*  a pointer to the top of the state    */
  68.                 /*  stack; only set during error    */
  69.                 /*  recovery.                */
  70.  
  71. YYSTYPE *yygvsp;        /*  a pointer to the top of the value    */
  72.                 /*  stack; only set during error    */
  73.                 /*  recovery.                */
  74.  
  75. YYLTYPE *yyglsp;        /*  a pointer to the top of the        */
  76.                 /*  location stack; only set during    */
  77.                 /*  error recovery.            */
  78.  
  79.  
  80. /*  Yyget is an interface between the parser and the lexical analyzer.    */
  81. /*  It is costly to provide such an interface, but it avoids requiring    */
  82. /*  the lexical analyzer to be able to back up the scan.        */
  83.  
  84. yyget()
  85. {
  86.   if (yynunlexed > 0)
  87.     {
  88.       yynunlexed--;
  89.       yychar = yyunchar[yynunlexed];
  90.       yylval = yyunval[yynunlexed];
  91.       yylloc = yyunloc[yynunlexed];
  92.     }
  93.   else if (yychar <= 0)
  94.     yychar = 0;
  95.   else
  96.     {
  97.       yychar = yylex();
  98.       if (yychar < 0)
  99.     yychar = 0;
  100.       else yychar = YYTRANSLATE(yychar);
  101.     }
  102. }
  103.  
  104.  
  105.  
  106. yyunlex(chr, val, loc)
  107. int chr;
  108. YYSTYPE val;
  109. YYLTYPE loc;
  110. {
  111.   yyunchar[yynunlexed] = chr;
  112.   yyunval[yynunlexed] = val;
  113.   yyunloc[yynunlexed] = loc;
  114.   yynunlexed++;
  115. }
  116.  
  117.  
  118.  
  119. yyrestore(first, last)
  120. register short *first;
  121. register short *last;
  122. {
  123.   register short *ssp;
  124.   register short *rp;
  125.   register int symbol;
  126.   register int state;
  127.   register int tvalsaved;
  128.  
  129.   ssp = yygssp;
  130.   yyunlex(yychar, yylval, yylloc);
  131.  
  132.   tvalsaved = 0;
  133.   while (first != last)
  134.     {
  135.       symbol = yystos[*ssp];
  136.       if (symbol < YYNTBASE)
  137.     {
  138.       yyunlex(symbol, yytval, yytloc);
  139.       tvalsaved = 1;
  140.       ssp--;
  141.     }
  142.  
  143.       ssp--;
  144.  
  145.       if (first == yyrq)
  146.     first = yyrq + YYMAXRULES;
  147.  
  148.       first--;
  149.  
  150.       for (rp = yyrhs + yyprhs[*first]; symbol = *rp; rp++)
  151.     {
  152.       if (symbol < YYNTBASE)
  153.         state = yytable[yypact[*ssp] + symbol];
  154.       else
  155.         {
  156.           state = yypgoto[symbol - YYNTBASE] + *ssp;
  157.  
  158.           if (state >= 0 && state <= YYLAST && yycheck[state] == *ssp)
  159.         state = yytable[state];
  160.           else
  161.         state = yydefgoto[symbol - YYNTBASE];
  162.         }
  163.  
  164.       *++ssp = state;
  165.     }
  166.     }
  167.  
  168.   if ( ! tvalsaved && ssp > yyss)
  169.     {
  170.       yyunlex(yystos[*ssp], yytval, yytloc);
  171.       ssp--;
  172.     }
  173.  
  174.   yygssp = ssp;
  175. }
  176.  
  177.  
  178.  
  179. int
  180. yyparse()
  181. {
  182.   register int yystate;
  183.   register int yyn;
  184.   register short *yyssp;
  185.   register short *yyrq0;
  186.   register short *yyptr;
  187.   register YYSTYPE *yyvsp;
  188.  
  189.   int yylen;
  190.   YYLTYPE *yylsp;
  191.   short *yyrq1;
  192.   short *yyrq2;
  193.  
  194.   yystate = 0;
  195.   yyssp = yyss - 1;
  196.   yyvsp = yyvs - 1;
  197.   yylsp = yyls - 1;
  198.   yyrq0 = yyrq;
  199.   yyrq1 = yyrq0;
  200.   yyrq2 = yyrq0;
  201.  
  202.   yychar = yylex();
  203.   if (yychar < 0)
  204.     yychar = 0;
  205.   else yychar = YYTRANSLATE(yychar);
  206.  
  207. yynewstate:
  208.  
  209.   if (yyssp >= yyss + YYMAXDEPTH - 1)
  210.     {
  211.       yyabort("Parser Stack Overflow");
  212.       YYABORT;
  213.     }
  214.  
  215.   *++yyssp = yystate;
  216.  
  217. yyresume:
  218.  
  219.   yyn = yypact[yystate];
  220.   if (yyn == YYFLAG)
  221.     goto yydefault;
  222.  
  223.   yyn += yychar;
  224.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar)
  225.     goto yydefault;
  226.  
  227.   yyn = yytable[yyn];
  228.   if (yyn < 0)
  229.     {
  230.       yyn = -yyn;
  231.       goto yyreduce;
  232.     }
  233.   else if (yyn == 0)
  234.     goto yyerrlab;
  235.  
  236.   yystate = yyn;
  237.  
  238.   yyptr = yyrq2;
  239.   while (yyptr != yyrq1)
  240.     {
  241.       yyn = *yyptr++;
  242.       yylen = yyr2[yyn];
  243.       yyvsp -= yylen;
  244.       yylsp -= yylen;
  245.  
  246.       yyguard(yyn, yyvsp, yylsp);
  247.       if (yyerror)
  248.     goto yysemerr;
  249.  
  250.       yyaction(yyn, yyvsp, yylsp);
  251.       *++yyvsp = yyval;
  252.  
  253.       yylsp++;
  254.       if (yylen == 0)
  255.     {
  256.       yylsp->timestamp = timeclock;
  257.       yylsp->first_line = yytloc.first_line;
  258.       yylsp->first_column = yytloc.first_column;
  259.       yylsp->last_line = (yylsp-1)->last_line;
  260.       yylsp->last_column = (yylsp-1)->last_column;
  261.       yylsp->text = 0;
  262.     }
  263.       else
  264.     {
  265.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  266.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  267.     }
  268.       
  269.       if (yyptr == yyrq + YYMAXRULES)
  270.         yyptr = yyrq;
  271.     }
  272.  
  273.   if (yystate == YYFINAL)
  274.     YYACCEPT;
  275.  
  276.   yyrq2 = yyptr;
  277.   yyrq1 = yyrq0;
  278.  
  279.   *++yyvsp = yytval;
  280.   *++yylsp = yytloc;
  281.   yytval = yylval;
  282.   yytloc = yylloc;
  283.   yyget();
  284.  
  285.   goto yynewstate;
  286.  
  287. yydefault:
  288.  
  289.   yyn = yydefact[yystate];
  290.   if (yyn == 0)
  291.     goto yyerrlab;
  292.  
  293. yyreduce:
  294.  
  295.   *yyrq0++ = yyn;
  296.  
  297.   if (yyrq0 == yyrq + YYMAXRULES)
  298.     yyrq0 = yyrq;
  299.  
  300.   if (yyrq0 == yyrq2)
  301.     {
  302.       yyabort("Parser Rule Queue Overflow");
  303.       YYABORT;
  304.     }
  305.  
  306.   yyssp -= yyr2[yyn];
  307.   yyn = yyr1[yyn];
  308.  
  309.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  310.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  311.     yystate = yytable[yystate];
  312.   else
  313.     yystate = yydefgoto[yyn - YYNTBASE];
  314.  
  315.   goto yynewstate;
  316.  
  317. yysemerr:
  318.   *--yyptr = yyn;
  319.   yyrq2 = yyptr;
  320.   yyvsp += yyr2[yyn];
  321.  
  322. yyerrlab:
  323.  
  324.   yygssp = yyssp;
  325.   yygvsp = yyvsp;
  326.   yyglsp = yylsp;
  327.   yyrestore(yyrq0, yyrq2);
  328.   yyrecover();
  329.   yystate = *yygssp;
  330.   yyssp = yygssp;
  331.   yyvsp = yygvsp;
  332.   yyrq0 = yyrq;
  333.   yyrq1 = yyrq0;
  334.   yyrq2 = yyrq0;
  335.   goto yyresume;
  336. }
  337.  
  338. /* Action file follows: */
  339. $
  340. /* End of Action file */
  341.